package com.mole.rbac.controller;

import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
	private final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
	@GetMapping("/hello")
	public Map<String, Object> hello(String name) {
		Map<String, Object> map = new HashMap<>();
		map.put("id", 1);
		map.put("age", 18);
		map.put("name", "hello:" + name);
		map.put("ip", getServiceIp());
		map.put("test", "test");
		return map;
	}
	@GetMapping("/healthcheck")
	public String healthcheck(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		LOGGER.debug("心跳监测:{}", format.format(new Date()));
		return "0";
	}
	/**
	 * 获取服务器ip
	 * @return
	 */
	private String getServiceIp() {
		InetAddress address;
		String myIp = "";
		try {
			address = InetAddress.getLocalHost();
			myIp = address.getHostAddress();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return myIp;
	}
}
